App({
  onLaunch: function () {
    tt.login({
      success(res) {
      console.log(`login调用成功${res.code} ${res.anonymousCode}`);
      var code = res.code;
      var anonymous_code = res.anonymousCode;

      let task = tt.request({
        url: "https://developer.toutiao.com/api/apps/jscode2session",
        data: {
          appid: "ttd09aa6274fa00b43",
          secret: "42a9a4c53344a1f1217cc53bd2625bb902acad76",
          code: code,
          anonymous_code: anonymous_code
        },
        header: {
          "content-type": "application/json"
        },
        success(res) {
          console.log(`request调用成功 ${res}`);
          console.log(res);
          var session_key = res.data.session_key;
          var openid = res.data.openid;
          var anonymous_openid = res.data.anonymous_openid;
          console.log(openid,"openid")
          try {
            tt.setStorageSync("openid", openid);
          } catch (error) {
            console.log(`setStorageSync调用失败`);
          }

          tt.checkSession({
            success() {
              console.log(`session未过期`);

              // tt.getUserInfo({
              //   success(res) {
              //     console.log(`getUserInfo 调用成功 ${res.userInfo}`);
              //     console.log(res,"授权")
              //   },
              //   fail(res) {
              //     console.log(`getUserInfo 调用失败`);
              //   }
              // });

           
            },
            fail() {
              console.log(`session已过期，需要重新登录`);
            }
          });
          
        },
        fail(res) {
          console.log(`request调用失败`);
        }
      });
      
      },
      fail(res) {
      console.log(`login调用失败`);
      }
    });
  }

})
